using System;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;

namespace My.IdlConverter.Core.Types
{
    public sealed class TypeFormatStrategyFactory
    {
        public static readonly string ReturnType = "ReturnType";
        public static readonly string ParameterType = "ParameterType";

        private static IDictionary<string, Type> _formatStrategies = new Dictionary<string,Type>();

        static TypeFormatStrategyFactory()
        {
            _formatStrategies.Add(ReturnType, Util.ReflectHelper.ClassForName(Cfg.Configuration.ReturnTypeFormatStrategy));
            _formatStrategies.Add(ParameterType, Util.ReflectHelper.ClassForName(Cfg.Configuration.ParameterTypeFormatStrategy));
        }

        public static ITypeFormatStrategy Create(string strategyName)
        {
            Type type = _formatStrategies[strategyName];
            ITypeFormatStrategy formatStrategy = Activator.CreateInstance(type) as ITypeFormatStrategy;
            Debug.Assert(formatStrategy != null);
            return formatStrategy;
        }
    }
}
